<template>
  <div>
    <!-- 实销变更申请 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="qjhActualSalesChange"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" @click="addHandle">新增</el-button>
      </template>
    </FilterTable>

    <Drawer :visible.sync="visible" :title="drawerTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, delDataById } from '@/api/dealerSale/SalesSanagement/ActualSalesChange';
import SonModel from './SonModel';

export default {
  name: 'ActualSalesChange',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '明细' };

    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {xhrAbort:true},
      formData: {},
      visible: false,
      handleType: '',
      drawerTitle: ''
    };
  },
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    // 搜索
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params, { xhrAbort:false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 新增
    addHandle() {
      this.handleType = 'add';
      this.formData = {};
      this.showHandler();
    },
    // 编辑
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    // 明细
    detailHandle(row) {
      this.handleType = 'show';
      this.formData = row;
      this.showHandler();
    },
    // 删除
    async delHandle(row) {
      await this.$confirm('确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await delDataById(row.id);
          if (res.resultCode == 200) {
            this.$message.success('删除成功!');
            this.fetchParams = { ...this.fetchParams };
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },

    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength:'',
          maxRows:2
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'customerPhone',
          placeholder: '请输入'
        },
        {
          type: 'RANGE_DATE',
          label: '开票日期',
          fieldName: 'invoiceDateStart|invoiceDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'RANGE_DATE',
          label: '实销通过日期',
          fieldName: 'reportPassDateStart|reportPassDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'SELECT',
          label: '变更状态',
          fieldName: 'changeStatus',
          placeholder: '请选择',
          itemList: [
            { text: '待提交', value: 60571001 },
            { text: '审核驳回', value: 60571002 },
            { text: '已作废', value: 60571004 }
          ]
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          width: 150,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" disabled={props.row.changeStatus == 60571004} onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </multiuse-button>
                <multiuse-button size="mini" type="text" disabled={props.row.changeStatus == 60571004} onClick={() => this.delHandle(props.row)}>
                  删除
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '变更状态',
          dataIndex: 'changeStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '待提交', value: 60571001 },
            { text: '审核驳回', value: 60571002 },
            { text: '已作废', value: 60571004 }
          ],
          render: props => {
            return <span>{this.createDictText(props.row.changeStatus, '6057')}</span>;
          }
        },
        {
          title: '零售单号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'customerSex',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.customerSex, '1002')}</span>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'mobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电话',
          dataIndex: 'phone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '使用人',
          dataIndex: 'userName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '使用人电话',
          dataIndex: 'userPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '身份证号',
          dataIndex: 'cardNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '年龄',
          dataIndex: 'age', // TODO 9407
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('9407'),
          render: props => {
            return <span>{this.createDictText(props.row.age, '9407')}</span>;
          }
        },
        {
          title: '学历',
          dataIndex: 'education', // TODO 4049
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('4049'),
          render: props => {
            return <span>{this.createDictText(props.row.education, '4049')}</span>;
          }
        },
        {
          title: '户口类型',
          dataIndex: 'residenceType', // TODO 7062
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7062'),
          render: props => {
            return <span>{this.createDictText(props.row.residenceType, '7062')}</span>;
          }
        },
        {
          title: '职业',
          dataIndex: 'occupation', // TODO 1527
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1527'),
          render: props => {
            return <span>{this.createDictText(props.row.occupation, '1527')}</span>;
          }
        },
        {
          title: '邮编',
          dataIndex: 'zipCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '地址',
          dataIndex: 'linkAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆形式',
          dataIndex: 'powerType', // TODO 6008
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: props => {
            return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          }
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '公告号',
          dataIndex: 'noticeNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimColorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '颜色',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '订单类型',
          dataIndex: 'orderType', // TODO 6026
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6026'),
          render: props => {
            return <span>{this.createDictText(props.row.orderType, '6026')}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'plateNumber',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售顾问',
          dataIndex: 'salesManName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType', // TODO 1523
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: props => {
            return <span>{this.createDictText(props.row.customerType, '1523')}</span>;
          }
        },

        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '县区',
          dataIndex: 'districtName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实销建档日期',
          dataIndex: 'reportCreateDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实销通过日期',
          dataIndex: 'reportPassDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '生产日期',
          dataIndex: 'productDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出库日期',
          dataIndex: 'stockOutData',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '入库日期',
          dataIndex: 'postingDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票号',
          dataIndex: 'invoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '交车日期',
          dataIndex: 'deliveryDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '市场指导价',
          dataIndex: 'basicPrice',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电机号',
          dataIndex: 'motorCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电池号',
          dataIndex: 'batteryNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '支付方式',
          dataIndex: 'payType', // TODO 6015
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6015'),
          render: props => {
            return <span>{this.createDictText(props.row.payType, '6015')}</span>;
          }
        },
        {
          title: '金融机构',
          dataIndex: 'financialInstitution', //TODO 9602
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('9602'),
          render: props => {
            return <span>{this.createDictText(props.row.financialInstitution, '9602')}</span>;
          }
        },
        {
          title: '期数',
          dataIndex: 'periodsNumber', // TODO 6061
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6061'),
          render: props => {
            return <span>{this.createDictText(props.row.periodsNumber, '6061')}</span>;
          }
        },
        {
          title: '上牌省份',
          dataIndex: 'plateProvinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '上牌城市',
          dataIndex: 'plateCityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆性质',
          dataIndex: 'vehicleType', // TODO 4103
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('4103'),
          render: props => {
            return <span>{this.createDictText(props.row.vehicleType, '4103')}</span>;
          }
        },
        {
          title: '是否大客户',
          dataIndex: 'isBigCustomerOrder', // TODO 1004
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isBigCustomerOrder, '1004')}</span>;
          }
        },
        {
          title: '大客户项目编号',
          dataIndex: 'majorContractNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否三方车辆',
          dataIndex: 'isTripartite', // TODO 1004
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isTripartite, '1004')}</span>;
          }
        },
        {
          title: '资金类型',
          dataIndex: 'accountTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '下线工厂',
          dataIndex: 'factoryName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '仓库',
          dataIndex: 'warehouseName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
